package b.g.b;

import b.g.b.h.c;
import java.util.Arrays;
import java.util.Objects;

/* compiled from: LinearSystem */
public class d {
    public static boolean p = false;
    public static int q = 1000;
    public static long r;
    public boolean a;
    public int b;
    public a c;
    public int d;
    public int e;
    public b[] f;
    public boolean g;
    public boolean[] h;
    public int i;
    public int j;
    public int k;
    public final c l;
    public g[] m;
    public int n;
    public a o;

    /* compiled from: LinearSystem */
    public interface a {
        void a(g gVar);

        g b(d dVar, boolean[] zArr);

        void clear();

        boolean isEmpty();
    }

    public d() {
        this.a = false;
        this.b = 0;
        this.d = 32;
        this.e = 32;
        this.f = null;
        this.g = false;
        this.h = new boolean[32];
        this.i = 1;
        this.j = 0;
        this.k = 32;
        this.m = new g[q];
        this.n = 0;
        this.f = new b[32];
        t();
        c cVar = new c();
        this.l = cVar;
        this.c = new f(cVar);
        this.o = new b(cVar);
    }

    public final g a(b.g.b.g.a aVar, String str) {
        g gVar = (g) this.l.c.a();
        if (gVar == null) {
            gVar = new g(aVar);
            gVar.i = aVar;
        } else {
            gVar.c();
            gVar.i = aVar;
        }
        int i = this.n;
        int i2 = q;
        if (i >= i2) {
            i2 *= 2;
            q = i2;
            this.m = (g[]) Arrays.copyOf(this.m, i2);
        }
        g[] gVarArr = this.m;
        i2 = this.n;
        this.n = i2 + 1;
        gVarArr[i2] = gVar;
        return gVar;
    }

    public void b(g gVar, g gVar2, int i, float f, g gVar3, g gVar4, int i2, int i3) {
        b m = m();
        if (gVar2 == gVar3) {
            m.d.g(gVar, 1.0f);
            m.d.g(gVar4, 1.0f);
            m.d.g(gVar2, -2.0f);
        } else if (f == 0.5f) {
            m.d.g(gVar, 1.0f);
            m.d.g(gVar2, -1.0f);
            m.d.g(gVar3, -1.0f);
            m.d.g(gVar4, 1.0f);
            if (i > 0 || i2 > 0) {
                m.b = (float) ((-i) + i2);
            }
        } else if (f <= 0.0f) {
            m.d.g(gVar, -1.0f);
            m.d.g(gVar2, 1.0f);
            m.b = (float) i;
        } else if (f >= 1.0f) {
            m.d.g(gVar4, -1.0f);
            m.d.g(gVar3, 1.0f);
            m.b = (float) (-i2);
        } else {
            float f2 = 1.0f - f;
            m.d.g(gVar, f2 * 1.0f);
            m.d.g(gVar2, f2 * -1.0f);
            m.d.g(gVar3, -1.0f * f);
            m.d.g(gVar4, 1.0f * f);
            if (i > 0 || i2 > 0) {
                m.b = (((float) i2) * f) + (((float) (-i)) * f2);
            }
        }
        if (i3 != 8) {
            m.c(this, i3);
        }
        c(m);
    }

    /* JADX WARNING: Removed duplicated region for block: B:111:0x01bc  */
    /* JADX WARNING: Removed duplicated region for block: B:110:0x01bb A:{RETURN} */
    public void c(b.g.b.b r17) {
        /*
        r16 = this;
        r0 = r16;
        r1 = r17;
        r2 = b.g.b.g.a.UNRESTRICTED;
        r3 = r0.j;
        r4 = 1;
        r3 = r3 + r4;
        r5 = r0.k;
        if (r3 >= r5) goto L_0x0015;
    L_0x000e:
        r3 = r0.i;
        r3 = r3 + r4;
        r5 = r0.e;
        if (r3 < r5) goto L_0x0018;
    L_0x0015:
        r16.p();
    L_0x0018:
        r3 = r1.e;
        if (r3 != 0) goto L_0x01be;
    L_0x001c:
        r3 = r0.f;
        r3 = r3.length;
        r6 = -1;
        if (r3 != 0) goto L_0x0023;
    L_0x0022:
        goto L_0x0085;
    L_0x0023:
        r3 = 0;
    L_0x0024:
        if (r3 != 0) goto L_0x0075;
    L_0x0026:
        r7 = r1.d;
        r7 = r7.e();
        r8 = 0;
    L_0x002d:
        if (r8 >= r7) goto L_0x0046;
    L_0x002f:
        r9 = r1.d;
        r9 = r9.i(r8);
        r10 = r9.c;
        if (r10 != r6) goto L_0x003e;
    L_0x0039:
        r10 = r9.f;
        if (r10 != 0) goto L_0x003e;
    L_0x003d:
        goto L_0x0043;
    L_0x003e:
        r10 = r1.c;
        r10.add(r9);
    L_0x0043:
        r8 = r8 + 1;
        goto L_0x002d;
    L_0x0046:
        r7 = r1.c;
        r7 = r7.size();
        if (r7 <= 0) goto L_0x0073;
    L_0x004e:
        r8 = 0;
    L_0x004f:
        if (r8 >= r7) goto L_0x006d;
    L_0x0051:
        r9 = r1.c;
        r9 = r9.get(r8);
        r9 = (b.g.b.g) r9;
        r10 = r9.f;
        if (r10 == 0) goto L_0x0061;
    L_0x005d:
        r1.k(r0, r9, r4);
        goto L_0x006a;
    L_0x0061:
        r10 = r0.f;
        r9 = r9.c;
        r9 = r10[r9];
        r1.l(r0, r9, r4);
    L_0x006a:
        r8 = r8 + 1;
        goto L_0x004f;
    L_0x006d:
        r7 = r1.c;
        r7.clear();
        goto L_0x0024;
    L_0x0073:
        r3 = 1;
        goto L_0x0024;
    L_0x0075:
        r3 = r1.a;
        if (r3 == 0) goto L_0x0085;
    L_0x0079:
        r3 = r1.d;
        r3 = r3.e();
        if (r3 != 0) goto L_0x0085;
    L_0x0081:
        r1.e = r4;
        r0.a = r4;
    L_0x0085:
        r3 = r17.isEmpty();
        if (r3 == 0) goto L_0x008c;
    L_0x008b:
        return;
    L_0x008c:
        r3 = r1.b;
        r7 = 0;
        r8 = (r3 > r7 ? 1 : (r3 == r7 ? 0 : -1));
        if (r8 >= 0) goto L_0x009e;
    L_0x0093:
        r8 = -1082130432; // 0xffffffffbf800000 float:-1.0 double:NaN;
        r3 = r3 * r8;
        r1.b = r3;
        r3 = r1.d;
        r3.k();
    L_0x009e:
        r3 = r1.d;
        r3 = r3.e();
        r9 = 0;
        r10 = 0;
        r11 = 0;
        r12 = 0;
        r13 = 0;
        r14 = 0;
        r15 = 0;
    L_0x00ab:
        if (r9 >= r3) goto L_0x0106;
    L_0x00ad:
        r5 = r1.d;
        r5 = r5.a(r9);
        r6 = r1.d;
        r6 = r6.i(r9);
        r8 = r6.i;
        if (r8 != r2) goto L_0x00dd;
    L_0x00bd:
        if (r10 != 0) goto L_0x00c5;
    L_0x00bf:
        r8 = r1.h(r6);
    L_0x00c3:
        r13 = r8;
        goto L_0x00ce;
    L_0x00c5:
        r8 = (r12 > r5 ? 1 : (r12 == r5 ? 0 : -1));
        if (r8 <= 0) goto L_0x00d1;
    L_0x00c9:
        r8 = r1.h(r6);
        goto L_0x00c3;
    L_0x00ce:
        r12 = r5;
        r10 = r6;
        goto L_0x0102;
    L_0x00d1:
        if (r13 != 0) goto L_0x0102;
    L_0x00d3:
        r8 = r1.h(r6);
        if (r8 == 0) goto L_0x0102;
    L_0x00d9:
        r12 = r5;
        r10 = r6;
        r13 = 1;
        goto L_0x0102;
    L_0x00dd:
        if (r10 != 0) goto L_0x0102;
    L_0x00df:
        r8 = (r5 > r7 ? 1 : (r5 == r7 ? 0 : -1));
        if (r8 >= 0) goto L_0x0102;
    L_0x00e3:
        if (r11 != 0) goto L_0x00eb;
    L_0x00e5:
        r8 = r1.h(r6);
    L_0x00e9:
        r15 = r8;
        goto L_0x00f4;
    L_0x00eb:
        r8 = (r14 > r5 ? 1 : (r14 == r5 ? 0 : -1));
        if (r8 <= 0) goto L_0x00f7;
    L_0x00ef:
        r8 = r1.h(r6);
        goto L_0x00e9;
    L_0x00f4:
        r14 = r5;
        r11 = r6;
        goto L_0x0102;
    L_0x00f7:
        if (r15 != 0) goto L_0x0102;
    L_0x00f9:
        r8 = r1.h(r6);
        if (r8 == 0) goto L_0x0102;
    L_0x00ff:
        r14 = r5;
        r11 = r6;
        r15 = 1;
    L_0x0102:
        r9 = r9 + 1;
        r6 = -1;
        goto L_0x00ab;
    L_0x0106:
        if (r10 == 0) goto L_0x0109;
    L_0x0108:
        goto L_0x010a;
    L_0x0109:
        r10 = r11;
    L_0x010a:
        if (r10 != 0) goto L_0x010e;
    L_0x010c:
        r3 = 1;
        goto L_0x0112;
    L_0x010e:
        r1.j(r10);
        r3 = 0;
    L_0x0112:
        r5 = r1.d;
        r5 = r5.e();
        if (r5 != 0) goto L_0x011c;
    L_0x011a:
        r1.e = r4;
    L_0x011c:
        if (r3 == 0) goto L_0x01a8;
    L_0x011e:
        r3 = r0.i;
        r3 = r3 + r4;
        r5 = r0.e;
        if (r3 < r5) goto L_0x0128;
    L_0x0125:
        r16.p();
    L_0x0128:
        r3 = b.g.b.g.a.SLACK;
        r5 = 0;
        r3 = r0.a(r3, r5);
        r5 = r0.b;
        r5 = r5 + r4;
        r0.b = r5;
        r6 = r0.i;
        r6 = r6 + r4;
        r0.i = r6;
        r3.b = r5;
        r6 = r0.l;
        r6 = r6.d;
        r6[r5] = r3;
        r1.a = r3;
        r5 = r0.j;
        r16.i(r17);
        r6 = r0.j;
        r5 = r5 + r4;
        if (r6 != r5) goto L_0x01a8;
    L_0x014d:
        r5 = r0.o;
        r5 = (b.g.b.b) r5;
        java.util.Objects.requireNonNull(r5);
        r6 = 0;
        r5.a = r6;
        r6 = r5.d;
        r6.clear();
        r6 = 0;
    L_0x015d:
        r8 = r1.d;
        r8 = r8.e();
        if (r6 >= r8) goto L_0x0179;
    L_0x0165:
        r8 = r1.d;
        r8 = r8.i(r6);
        r9 = r1.d;
        r9 = r9.a(r6);
        r10 = r5.d;
        r10.b(r8, r9, r4);
        r6 = r6 + 1;
        goto L_0x015d;
    L_0x0179:
        r5 = r0.o;
        r0.s(r5);
        r5 = r3.c;
        r6 = -1;
        if (r5 != r6) goto L_0x01a6;
    L_0x0183:
        r5 = r1.a;
        if (r5 != r3) goto L_0x0191;
    L_0x0187:
        r5 = 0;
        r3 = r1.i(r5, r3);
        if (r3 == 0) goto L_0x0191;
    L_0x018e:
        r1.j(r3);
    L_0x0191:
        r3 = r1.e;
        if (r3 != 0) goto L_0x019a;
    L_0x0195:
        r3 = r1.a;
        r3.e(r0, r1);
    L_0x019a:
        r3 = r0.l;
        r3 = r3.b;
        r3.b(r1);
        r3 = r0.j;
        r3 = r3 - r4;
        r0.j = r3;
    L_0x01a6:
        r3 = 1;
        goto L_0x01a9;
    L_0x01a8:
        r3 = 0;
    L_0x01a9:
        r5 = r1.a;
        if (r5 == 0) goto L_0x01b8;
    L_0x01ad:
        r5 = r5.i;
        if (r5 == r2) goto L_0x01b9;
    L_0x01b1:
        r2 = r1.b;
        r2 = (r2 > r7 ? 1 : (r2 == r7 ? 0 : -1));
        if (r2 < 0) goto L_0x01b8;
    L_0x01b7:
        goto L_0x01b9;
    L_0x01b8:
        r4 = 0;
    L_0x01b9:
        if (r4 != 0) goto L_0x01bc;
    L_0x01bb:
        return;
    L_0x01bc:
        r5 = r3;
        goto L_0x01bf;
    L_0x01be:
        r5 = 0;
    L_0x01bf:
        if (r5 != 0) goto L_0x01c4;
    L_0x01c1:
        r16.i(r17);
    L_0x01c4:
        return;
        */
        throw new UnsupportedOperationException("Method not decompiled: b.g.b.d.c(b.g.b.b):void");
    }

    public b d(g gVar, g gVar2, int i, int i2) {
        if (i2 == 8 && gVar2.f && gVar.c == -1) {
            gVar.d(this, gVar2.e + ((float) i));
            return null;
        }
        b m = m();
        Object obj = null;
        if (i != 0) {
            if (i < 0) {
                i *= -1;
                obj = 1;
            }
            m.b = (float) i;
        }
        if (obj == null) {
            m.d.g(gVar, -1.0f);
            m.d.g(gVar2, 1.0f);
        } else {
            m.d.g(gVar, 1.0f);
            m.d.g(gVar2, -1.0f);
        }
        if (i2 != 8) {
            m.c(this, i2);
        }
        c(m);
        return m;
    }

    public void e(g gVar, int i) {
        int i2 = gVar.c;
        if (i2 == -1) {
            gVar.d(this, (float) i);
            for (int i3 = 0; i3 < this.b + 1; i3++) {
                g gVar2 = this.l.d[i3];
            }
            return;
        }
        b bVar;
        if (i2 != -1) {
            bVar = this.f[i2];
            if (bVar.e) {
                bVar.b = (float) i;
            } else if (bVar.d.e() == 0) {
                bVar.e = true;
                bVar.b = (float) i;
            } else {
                bVar = m();
                if (i < 0) {
                    bVar.b = (float) (i * -1);
                    bVar.d.g(gVar, 1.0f);
                } else {
                    bVar.b = (float) i;
                    bVar.d.g(gVar, -1.0f);
                }
                c(bVar);
            }
        } else {
            bVar = m();
            bVar.a = gVar;
            float f = (float) i;
            gVar.e = f;
            bVar.b = f;
            bVar.e = true;
            c(bVar);
        }
    }

    public void f(g gVar, g gVar2, int i, int i2) {
        b m = m();
        g n = n();
        n.d = 0;
        m.e(gVar, gVar2, n, i);
        if (i2 != 8) {
            int c = (int) (m.d.c(n) * -1.0f);
            m.d.g(k(i2, null), (float) c);
        }
        c(m);
    }

    public void g(g gVar, g gVar2, int i, int i2) {
        b m = m();
        g n = n();
        n.d = 0;
        m.f(gVar, gVar2, n, i);
        if (i2 != 8) {
            int c = (int) (m.d.c(n) * -1.0f);
            m.d.g(k(i2, null), (float) c);
        }
        c(m);
    }

    public void h(g gVar, g gVar2, g gVar3, g gVar4, float f, int i) {
        b m = m();
        m.d(gVar, gVar2, gVar3, gVar4, f);
        if (i != 8) {
            m.c(this, i);
        }
        c(m);
    }

    public final void i(b bVar) {
        int i;
        if (bVar.e) {
            bVar.a.d(this, bVar.b);
        } else {
            b[] bVarArr = this.f;
            i = this.j;
            bVarArr[i] = bVar;
            g gVar = bVar.a;
            gVar.c = i;
            this.j = i + 1;
            gVar.e(this, bVar);
        }
        if (this.a) {
            int i2 = 0;
            while (i2 < this.j) {
                if (this.f[i2] == null) {
                    System.out.println("WTF");
                }
                b[] bVarArr2 = this.f;
                if (bVarArr2[i2] != null && bVarArr2[i2].e) {
                    int i3;
                    b bVar2 = bVarArr2[i2];
                    bVar2.a.d(this, bVar2.b);
                    this.l.b.b(bVar2);
                    this.f[i2] = null;
                    i = i2 + 1;
                    int i4 = i;
                    while (true) {
                        i3 = this.j;
                        if (i >= i3) {
                            break;
                        }
                        b[] bVarArr3 = this.f;
                        i3 = i - 1;
                        bVarArr3[i3] = bVarArr3[i];
                        if (bVarArr3[i3].a.c == i) {
                            bVarArr3[i3].a.c = i3;
                        }
                        i4 = i;
                        i++;
                    }
                    if (i4 < i3) {
                        this.f[i4] = null;
                    }
                    this.j = i3 - 1;
                    i2--;
                }
                i2++;
            }
            this.a = false;
        }
    }

    public final void j() {
        for (int i = 0; i < this.j; i++) {
            b bVar = this.f[i];
            bVar.a.e = bVar.b;
        }
    }

    public g k(int i, String str) {
        if (this.i + 1 >= this.e) {
            p();
        }
        g a = a(b.g.b.g.a.ERROR, str);
        int i2 = this.b + 1;
        this.b = i2;
        this.i++;
        a.b = i2;
        a.d = i;
        this.l.d[i2] = a;
        this.c.a(a);
        return a;
    }

    public g l(Object obj) {
        g gVar = null;
        if (obj == null) {
            return null;
        }
        if (this.i + 1 >= this.e) {
            p();
        }
        if (obj instanceof c) {
            c cVar = (c) obj;
            gVar = cVar.i;
            if (gVar == null) {
                cVar.i();
                gVar = cVar.i;
            }
            int i = gVar.b;
            if (i == -1 || i > this.b || this.l.d[i] == null) {
                if (i != -1) {
                    gVar.c();
                }
                i = this.b + 1;
                this.b = i;
                this.i++;
                gVar.b = i;
                gVar.i = b.g.b.g.a.UNRESTRICTED;
                this.l.d[i] = gVar;
            }
        }
        return gVar;
    }

    public b m() {
        b bVar = (b) this.l.b.a();
        if (bVar == null) {
            bVar = new b(this.l);
            r++;
        } else {
            bVar.a = null;
            bVar.d.clear();
            bVar.b = 0.0f;
            bVar.e = false;
        }
        g.n++;
        return bVar;
    }

    public g n() {
        if (this.i + 1 >= this.e) {
            p();
        }
        g a = a(b.g.b.g.a.SLACK, null);
        int i = this.b + 1;
        this.b = i;
        this.i++;
        a.b = i;
        this.l.d[i] = a;
        return a;
    }

    public int o(Object obj) {
        g gVar = ((c) obj).i;
        return gVar != null ? (int) (gVar.e + 0.5f) : 0;
    }

    public final void p() {
        int i = this.d * 2;
        this.d = i;
        this.f = (b[]) Arrays.copyOf(this.f, i);
        c cVar = this.l;
        cVar.d = (g[]) Arrays.copyOf(cVar.d, this.d);
        i = this.d;
        this.h = new boolean[i];
        this.e = i;
        this.k = i;
    }

    public void q() throws Exception {
        if (this.c.isEmpty()) {
            j();
            return;
        }
        if (this.g) {
            Object obj = null;
            for (int i = 0; i < this.j; i++) {
                if (!this.f[i].e) {
                    break;
                }
            }
            obj = 1;
            if (obj == null) {
                r(this.c);
            } else {
                j();
            }
        } else {
            r(this.c);
        }
    }

    public void r(a aVar) throws Exception {
        float f;
        int i;
        Object obj;
        b.g.b.g.a aVar2 = b.g.b.g.a.UNRESTRICTED;
        int i2 = 0;
        while (true) {
            f = 0.0f;
            i = 1;
            if (i2 >= this.j) {
                obj = null;
                break;
            }
            b[] bVarArr = this.f;
            if (bVarArr[i2].a.i != aVar2 && bVarArr[i2].b < 0.0f) {
                obj = 1;
                break;
            }
            i2++;
        }
        if (obj != null) {
            obj = null;
            int i3 = 0;
            while (obj == null) {
                g i4;
                i3 += i;
                float f2 = Float.MAX_VALUE;
                int i5 = 0;
                int i6 = -1;
                int i7 = -1;
                int i8 = 0;
                while (i5 < this.j) {
                    b bVar = this.f[i5];
                    if (!(bVar.a.i == aVar2 || bVar.e || bVar.b >= r5)) {
                        int e = bVar.d.e();
                        int i9 = 0;
                        while (i9 < e) {
                            i4 = bVar.d.i(i9);
                            float c = bVar.d.c(i4);
                            if (c > f) {
                                int i10 = 0;
                                while (i10 < 9) {
                                    float f3 = i4.g[i10] / c;
                                    if ((f3 < f2 && i10 == r12) || i10 > r12) {
                                        i7 = i4.b;
                                        i8 = i10;
                                        f2 = f3;
                                        i6 = i5;
                                    }
                                    i10++;
                                }
                            }
                            i9++;
                            f = 0.0f;
                        }
                    }
                    i5++;
                    f = 0.0f;
                }
                if (i6 != -1) {
                    b bVar2 = this.f[i6];
                    bVar2.a.c = -1;
                    bVar2.j(this.l.d[i7]);
                    i4 = bVar2.a;
                    i4.c = i6;
                    i4.e(this, bVar2);
                } else {
                    obj = 1;
                }
                if (i3 > this.i / 2) {
                    obj = 1;
                }
                f = 0.0f;
                i = 1;
            }
        }
        s(aVar);
        j();
    }

    public final int s(a aVar) {
        for (int i = 0; i < this.i; i++) {
            this.h[i] = false;
        }
        Object obj = null;
        int i2 = 0;
        while (obj == null) {
            i2++;
            if (i2 >= this.i * 2) {
                return i2;
            }
            g gVar = ((b) aVar).a;
            if (gVar != null) {
                this.h[gVar.b] = true;
            }
            gVar = aVar.b(this, this.h);
            if (gVar != null) {
                boolean[] zArr = this.h;
                int i3 = gVar.b;
                if (zArr[i3]) {
                    return i2;
                }
                zArr[i3] = true;
            }
            if (gVar != null) {
                float f = Float.MAX_VALUE;
                int i4 = -1;
                for (int i5 = 0; i5 < this.j; i5++) {
                    b bVar = this.f[i5];
                    if (!(bVar.a.i == b.g.b.g.a.UNRESTRICTED || bVar.e || !bVar.d.d(gVar))) {
                        float c = bVar.d.c(gVar);
                        if (c < 0.0f) {
                            float f2 = (-bVar.b) / c;
                            if (f2 < f) {
                                i4 = i5;
                                f = f2;
                            }
                        }
                    }
                }
                if (i4 > -1) {
                    b bVar2 = this.f[i4];
                    bVar2.a.c = -1;
                    bVar2.j(gVar);
                    gVar = bVar2.a;
                    gVar.c = i4;
                    gVar.e(this, bVar2);
                }
            } else {
                obj = 1;
            }
        }
        return i2;
    }

    public final void t() {
        for (int i = 0; i < this.j; i++) {
            Object obj = this.f[i];
            if (obj != null) {
                this.l.b.b(obj);
            }
            this.f[i] = null;
        }
    }

    public void u() {
        c cVar;
        int i = 0;
        while (true) {
            cVar = this.l;
            g[] gVarArr = cVar.d;
            if (i >= gVarArr.length) {
                break;
            }
            g gVar = gVarArr[i];
            if (gVar != null) {
                gVar.c();
            }
            i++;
        }
        e eVar = cVar.c;
        g[] gVarArr2 = this.m;
        int i2 = this.n;
        Objects.requireNonNull(eVar);
        if (i2 > gVarArr2.length) {
            i2 = gVarArr2.length;
        }
        for (int i3 = 0; i3 < i2; i3++) {
            g gVar2 = gVarArr2[i3];
            int i4 = eVar.b;
            Object[] objArr = eVar.a;
            if (i4 < objArr.length) {
                objArr[i4] = gVar2;
                eVar.b = i4 + 1;
            }
        }
        this.n = 0;
        Arrays.fill(this.l.d, null);
        this.b = 0;
        this.c.clear();
        this.i = 1;
        for (i = 0; i < this.j; i++) {
            b[] bVarArr = this.f;
            if (bVarArr[i] != null) {
                Objects.requireNonNull(bVarArr[i]);
            }
        }
        t();
        this.j = 0;
        this.o = new b(this.l);
    }
}
